package com.mopub.nativeads; import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.content.pm.PackageManager; import android.net.Uri; import android.os.AsyncTask; import android.support.v4.app.NotificationCompat; import android.text.TextUtils; import android.view.View; import cn.wps.moffice.OfficeApp; import cn.wps.moffice.define.VersionManager; import cn.wps.moffice.main.ad.s2s.CommonBean; import cn.wps.moffice.main.info.DeviceInfo; import cn.wps.moffice_eng.R; import cn.wps.util.JSONUtil; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.mopub.common.CacheService; import com.mopub.mobileads.VideoDownloader; import com.mopub.nativeads.CustomEventNative; import com.mopub.nativeads.NativeImageHelper; import defpackage.ffi; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.json.JSONObject; public class KS2SEventNative extends CustomEventNative { public static final String GIF = ".gif"; public static final String HOME_POSITION = "home"; public static final String MP4 = ".mp4"; public static final String SCHEME_FILE = "file"; /* access modifiers changed from: package-private */ public static class a extends StaticNativeAd { public static final String AD_API_AD; public static final String AD_API_TRACK; public static final String AD_API_TRACK_CLICK; public static final String AD_HOST_CN = "https://cloudservice22.kingsoft-office-service.com/"; public static final String AD_HOST_EN = "https://abroad-ad.kingsoft-office-service.com/"; private Map<String, Object> BkJ; private String BrY; private final CustomEventNative.CustomEventNativeListener Brp; private CommonBean BsA; private boolean BsB; private int BsC; private boolean BsD; private List<CommonBean> Bsz; private ffi<CommonBean> cKZ; private String mAdType; private final Context mContext; /* renamed from: com.mopub.nativeads.KS2SEventNative$a$a reason: collision with other inner class name */ class C0111a extends cxs { final /* synthetic */ a BsF; private WeakReference<StaticNativeAd> BsG; private String fFO; private HashMap<String, String> fGe; private boolean fGf = false; private WeakReference<View> mView; public C0111a(a aVar, StaticNativeAd staticNativeAd, View view, CommonBean commonBean, String str, boolean z) { boolean z2 = false; this.BsF = aVar; this.BsG = new WeakReference<>(staticNativeAd); this.mView = new WeakReference<>(view); this.fGe = commonBean.getGaEvent(); this.fFO = str; this.cKF = (!z || bYG()) ? true : z2; super.d(commonBean.pkg, commonBean.button, commonBean.click_url, commonBean.icon); setup(); } private boolean bYG() { return "splash".equals(this.fFO) && hch.bYG(); } /* access modifiers changed from: protected */ @Override // defpackage.cxs public final void handler(int i, float f, long j) { StaticNativeAd staticNativeAd = this.BsG.get(); if (staticNativeAd != null) { switch (i) { case 0: staticNativeAd.setCallToAction(getText(R.string.public_waiting_download)); return; case 1: staticNativeAd.setCallToAction(String.format(getText(R.string.public_downloading_percent), Float.valueOf(f))); return; case 2: case 4: staticNativeAd.setCallToAction(getText(R.string.public_continue_download)); return; case 3: staticNativeAd.setCallToAction(getText(R.string.public_installd)); return; case 5: dhs.a(this.cKE, this); staticNativeAd.setCallToAction(getText(R.string.public_open)); return; default: if (TextUtils.isEmpty(this.cKE)) { staticNativeAd.setCallToAction(getText(R.string.public_download_immediately)); return; } else { staticNativeAd.setCallToAction(this.cKE); return; } } } } public final void onClick(final View view) { if (this.mStatus != -1) { this.BsF.gQn(); } switch (this.mStatus) { case -1: if (!this.fGf && this.cKF) { this.fGf = true; if ((!lwd.isWifiConnected(this.BsF.mContext) && lwd.hv(this.BsF.mContext)) || bYG()) { if (this.BsF.Bxg != null) { this.BsF.Bxg.buttonClick(); } czq czq = new czq(view.getContext()); int i = R.string.public_not_wifi_and_confirm; if (bYG()) { i = (lwd.isWifiConnected(this.BsF.mContext) || !lwd.hv(this.BsF.mContext)) ? R.string.public_wifi_and_confirm_download : R.string.public_not_wifi_and_confirm_download; czq.setTitleById(R.string.public_confirm_title_tips); } czq.setMessage(i); czq.setPositiveButton(R.string.public_continue, new DialogInterface.OnClickListener() { /* class com.mopub.nativeads.KS2SEventNative.a.C0111a.AnonymousClass1 */ public final void onClick(DialogInterface dialogInterface, int i) { view.performClick(); } }); czq.setNegativeButton(R.string.public_cancel, new DialogInterface.OnClickListener() { /* class com.mopub.nativeads.KS2SEventNative.a.C0111a.AnonymousClass2 */ public final void onClick(DialogInterface dialogInterface, int i) { if (C0111a.this.BsF.Bxg != null) { C0111a.this.BsF.Bxg.dismiss(); } } }); czq.setOnDismissListener(new DialogInterface.OnDismissListener() { /* class com.mopub.nativeads.KS2SEventNative.a.C0111a.AnonymousClass3 */ public final void onDismiss(DialogInterface dialogInterface) { if (C0111a.this.BsF.Bxg != null) { C0111a.this.BsF.Bxg.dismiss(); } } }); czq.show(); dwp.l(String.format("operation_ad_%s_download_show", this.fFO + (lwd.isWifiConnected(OfficeApp.arx()) ? "_wifi" : "_no_wifi")), this.fGe); return; } } hea.v(this.BsF.BsA.click_tracking_url); dwp.l(String.format("operation_ad_%s_download_click", this.fFO + (lwd.isWifiConnected(OfficeApp.arx()) ? "_wifi" : "_no_wifi")), this.fGe); if (!dhr.jI(this.mTag) && !dhr.jH(this.mPath)) { if (!lwd.hx(OfficeApp.arx())) { lvg.d(OfficeApp.arx(), R.string.documentmanager_qing_roamingdoc_no_network_operation_fail, 0); return; } else { lvg.d(OfficeApp.arx(), R.string.documentmanager_auto_update_title, 0); awZ(); } } this.BsF.gQn(); return; case 0: case 1: if (!lwd.hx(OfficeApp.arx())) { lvg.d(OfficeApp.arx(), R.string.documentmanager_qing_roamingdoc_no_network_operation_fail, 0); return; } View view2 = this.mView.get(); if (view2 != null) { fvf.ah((Activity) view2.getContext()); return; } return; case 2: case 4: if (!dhr.jI(this.mTag) && !dhr.jH(this.mPath)) { if (!lwd.hx(OfficeApp.arx())) { lvg.d(OfficeApp.arx(), R.string.documentmanager_qing_roamingdoc_no_network_operation_fail, 0); return; } else { awZ(); return; } } else { return; } case 3: dwp.l(String.format("operation_ad_%s_download_completed", this.fFO), this.fGe); axa(); return; case 5: dwp.l(String.format("operation_ad_%s_download_install", this.fFO), this.fGe); axb(); return; default: return; } } } class b extends AsyncTask<Void, Void, Integer> { private b() { } /* synthetic */ b(a aVar, byte b) { this(); } private Integer axO() { String gQt = a.this.gQt(); if (TextUtils.isEmpty(gQt)) { return -1; } try { JSONObject jSONObject = new JSONObject(lwd.f(gQt, null)); if (!TextUtils.isEmpty(jSONObject.getString(NotificationCompat.CATEGORY_ERROR))) { return -2; } List list = (List) JSONUtil.getGson().fromJson(jSONObject.getString("ads"), new TypeToken<List<CommonBean>>() { /* class com.mopub.nativeads.KS2SEventNative.a.b.AnonymousClass1 */ }.getType()); a.a(a.this, list); a.this.Bsz = list; if (a.this.Bsz == null || a.this.Bsz.size() == 0) { return -3; } a.this.BsA = (CommonBean) a.this.Bsz.get(0); a.this.BsC = a.this.BsA.ad_format; a.this.BsB = new fgw().e(a.this.BsA); if (a.this.BsB) { KsoAdReport.reportAdPreloadValid(a.this.BkJ, a.this.BsA.adfrom); } return 1; } catch (Exception e) { e.printStackTrace(); return -3; } } /* Return type fixed from 'java.lang.Object' to match base method */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object[]] */ /* access modifiers changed from: protected */ @Override // android.os.AsyncTask public final /* synthetic */ Integer doInBackground(Void[] voidArr) { return axO(); } /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ /* access modifiers changed from: protected */ @Override // android.os.AsyncTask public final /* synthetic */ void onPostExecute(Integer num) { switch (num.intValue()) { case -3: a.this.Brp.onNativeAdFailed(NativeErrorCode.ERROR_KSO_S2S_RESPONSE_PARSE_ERR); return; case -2: a.this.Brp.onNativeAdFailed(NativeErrorCode.ERROR_KSO_S2S_RESPONSE_ERROR_STR); return; case -1: a.this.Brp.onNativeAdFailed(NativeErrorCode.ERROR_KSO_S2S_URL_ILLEGAL); return; case 0: default: a.this.Brp.onNativeAdFailed(NativeErrorCode.UNSPECIFIED); return; case 1: if (a.this.gQu() || a.this.getRenderFormat() != 0) { a.j(a.this); return; } else { a.this.Brp.onNativeAdLoaded(a.this); return; } } } } static { String str = VersionManager.aYQ() ? AD_HOST_CN : AD_HOST_EN; AD_API_AD = str + "ad"; AD_API_TRACK = str + "show_track"; AD_API_TRACK_CLICK = str + "click"; } a(Context context, CustomEventNative.CustomEventNativeListener customEventNativeListener, String str, String str2, Map<String, Object> map) { this(context, customEventNativeListener, str, str2, map, null); } a(Context context, CustomEventNative.CustomEventNativeListener customEventNativeListener, String str, String str2, Map<String, Object> map, CommonBean commonBean) { this.BsB = false; this.BrY = ""; this.BsD = false; this.mContext = context; this.Brp = customEventNativeListener; this.mAdType = str; this.BrY = str2; this.BkJ = map; Object obj = this.BkJ.get(MopubLocalExtra.KEY_FORBID_INNER_DOWNLOAD_DIALOG); if (obj != null) { this.BsD = ((Boolean) obj).booleanValue(); } ffi.c cVar = new ffi.c(); cVar.fFO = str2; this.cKZ = cVar.cx(this.mContext); this.BsA = commonBean; u(this.BsA); } private static boolean L(Context context, String str) { if (str == null || "".equals(str)) { return false; } try { return context.getPackageManager().getApplicationInfo(str, 8192) != null; } catch (PackageManager.NameNotFoundException e) { return false; } } static /* synthetic */ void a(a aVar, List list) { Iterator it = list.iterator(); while (it.hasNext()) { CommonBean commonBean = (CommonBean) it.next(); if ("deeplink".equals(commonBean.browser_type)) { if (fgv.f(commonBean.browser_type, commonBean.pkg, commonBean.deeplink, commonBean.click_url)) { } } else if (commonBean != null) { if (!"APP".equals(commonBean.jump) || !L(OfficeApp.arx(), commonBean.pkg)) { if (!("home".equals(aVar.BrY) && (TextUtils.isEmpty(commonBean.title) || (TextUtils.isEmpty(commonBean.icon) && TextUtils.isEmpty(commonBean.background))))) { } } } it.remove(); } } private boolean axj() { return "APP".equals(this.BsA.jump) && !"deeplink".equals(this.BsA.browser_type); } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private String gQt() { Object obj; OfficeApp arx = OfficeApp.arx(); int gF = luf.gF(arx); int gG = luf.gG(arx); DeviceInfo deviceInfo = new DeviceInfo(); deviceInfo.dh(arx); boolean booleanValue = (this.BkJ == null || this.BkJ.size() <= 0 || (obj = this.BkJ.get(MopubLocalExtra.KEY_SPLASH_LOG)) == null) ? true : ((Boolean) obj).booleanValue(); if (luf.gQ(arx)) { int max = Math.max(gF, gG); deviceInfo.cP(booleanValue ? max - ((int) (100.0f * deviceInfo.dip)) : max, Math.min(gG, gF)); } else { int i = 660; int i2 = 440; if (luf.gN(arx)) { i = 500; i2 = 332; } deviceInfo.cP((int) (((float) i) * deviceInfo.dip), (int) (((float) i2) * deviceInfo.dip)); } try { String bKx = deviceInfo.bKx(); Uri.Builder buildUpon = Uri.parse(AD_API_AD).buildUpon(); buildUpon.encodedQuery(bKx); buildUpon.appendQueryParameter("ad_type", String.valueOf(this.mAdType)); buildUpon.appendQueryParameter("api_version", "3"); buildUpon.appendQueryParameter("pkg", fzy.bKz()); buildUpon.toString(); return buildUpon.toString(); } catch (Exception e) { e.printStackTrace(); return null; } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private boolean gQu() { return "splash".equals(KsoAdReport.getAdPlacement(this.BkJ)); } static /* synthetic */ void j(a aVar) { if (!TextUtils.isEmpty(aVar.BsA.video.video_url) && aVar.gQu()) { aVar.BsA.background = aVar.BsA.video.video_url; } aVar.u(aVar.BsA); String mainImageUrl = aVar.getMainImageUrl(); if (aVar.BsA.ad_format != 0 || !aVar.gQu()) { ArrayList arrayList = new ArrayList(); if (!TextUtils.isEmpty(mainImageUrl)) { arrayList.add(aVar.getMainImageUrl()); } if (!TextUtils.isEmpty(aVar.getIconImageUrl())) { arrayList.add(aVar.getIconImageUrl()); } NativeImageHelper.preCacheImages(aVar.mContext, arrayList, new NativeImageHelper.ImageListener() { /* class com.mopub.nativeads.KS2SEventNative.a.AnonymousClass3 */ @Override // com.mopub.nativeads.NativeImageHelper.ImageListener public final void onImagesCached() { } @Override // com.mopub.nativeads.NativeImageHelper.ImageListener public final void onImagesFailedToCache(NativeErrorCode nativeErrorCode) { } }); aVar.Brp.onNativeAdLoaded(aVar); } else if (!TextUtils.isEmpty(mainImageUrl)) { CacheService.initializeDiskCache(aVar.mContext); Uri parse = Uri.parse(mainImageUrl); boolean z = parse != null && !TextUtils.isEmpty(parse.getPath()) && KS2SEventNative.SCHEME_FILE.equalsIgnoreCase(parse.getScheme()); if (CacheService.containsKeyDiskCache(mainImageUrl) || z) { aVar.Brp.onNativeAdLoaded(aVar); } else { VideoDownloader.cache(mainImageUrl, new VideoDownloader.VideoDownloaderListener() { /* class com.mopub.nativeads.KS2SEventNative.a.AnonymousClass2 */ @Override // com.mopub.mobileads.VideoDownloader.VideoDownloaderListener public final void onComplete(boolean z) { if (z) { a.this.Brp.onNativeAdLoaded(a.this); } else { a.this.Brp.onNativeAdFailed(NativeErrorCode.ERROR_KSO_S2S_RESOURCE_FAILED_TO_DOWNLOAD_ERR); } } }); } } else { aVar.Brp.onNativeAdFailed(NativeErrorCode.ERROR_KSO_S2S_RESPONSE_ERROR_STR); } } private void u(CommonBean commonBean) { if (commonBean != null) { if (axj() && TextUtils.isEmpty(commonBean.button)) { commonBean.button = this.mContext.getResources().getString(R.string.public_download_immediately); } setTitle(commonBean.title); setText(commonBean.desc); setMainImageUrl(commonBean.background); setIconImageUrl(commonBean.icon); setCallToAction(commonBean.button); try { setKsoS2sAd(new Gson().toJson(commonBean)); } catch (Exception e) { } } } public final String getAdPosition() { return this.BrY; } public final String getAdType() { return this.mAdType; } public final List<CommonBean> getCommonBeanList() { return this.Bsz; } public final Context getContext() { return this.mContext; } public final CustomEventNative.CustomEventNativeListener getCustomEventNativeListener() { return this.Brp; } public final Map<String, Object> getLocalExtras() { return this.BkJ; } public final int getRenderFormat() { return this.BsC; } public final String getSegment(String str) { if (!TextUtils.isEmpty(str)) { String lastPathSegment = Uri.parse(str).getLastPathSegment(); int lastIndexOf = TextUtils.isEmpty(lastPathSegment) ? 0 : lastPathSegment.lastIndexOf("."); if (lastIndexOf >= 0 && lastPathSegment != null) { return lastPathSegment.substring(lastIndexOf); } } return ""; } public final boolean isDownloadApp() { if (this.BsA != null) { return axj(); } return false; } @Override // com.mopub.nativeads.StaticNativeAd, com.mopub.nativeads.BaseNativeAd public final void prepare(View view) { super.prepare(view); hea.v(this.BsA.impr_tracking_url); final String adPlacement = KsoAdReport.getAdPlacement(this.BkJ); if (axj()) { dwp.l(String.format("operation_ad_%s_download_show", adPlacement), this.BsA.getGaEvent()); view.setOnClickListener(new C0111a(this, this, view, this.BsA, adPlacement, this.BsD)); } else { view.setOnClickListener(new View.OnClickListener() { /* class com.mopub.nativeads.KS2SEventNative.a.AnonymousClass1 */ public final void onClick(View view) { String str = a.this.BsA.browser_type; if (!"splash".equals(adPlacement) || ((!"webview".equals(str) && !"readwebview".equals(str) && !"popwebview".equals(str)) || !TextUtils.isEmpty(a.this.BsA.click_url))) { hea.v(a.this.BsA.click_tracking_url); a.this.cKZ.b(a.this.mContext, a.this.BsA); a.this.gQn(); } } }); } KsoAdReport.reportAdIsPreloadShow(this.BkJ, this.BsA.adfrom, this.BsB); } public final void setCommonBean(CommonBean commonBean) { this.BsA = commonBean; } } /* access modifiers changed from: protected */ @Override // com.mopub.nativeads.CustomEventNative public final void a(Activity activity, MoPubAdRenderer moPubAdRenderer, CustomEventNative.CustomEventNativeListener customEventNativeListener, Map<String, Object> map, Map<String, String> map2) { String str = map2.get("ad_type"); if (str != null && str.length() > 0) { new a.b(new a(activity, customEventNativeListener, map2.get("ad_type"), KsoAdReport.getAdPlacement(map), map), (byte) 0).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]); } else { customEventNativeListener.onNativeAdFailed(NativeErrorCode.NATIVE_ADAPTER_CONFIGURATION_ERROR); } } }